package com.wc.alorithm_luogu.P1563;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/4/25 16:21
 * @description https://www.luogu.com.cn/problem/P1563
 * 玩具谜题
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());

        // 用数组存储小人 因为是逆时针，所以从后往前弄
        People[] peoples = new People[n];
        while (n-- > 0) {
            People people = new People();
            peoples[n] = people;
            people.outOrIn = Integer.parseInt(sc.next());
            people.name = sc.next();
        }
        // 表示当前位置
        int index = peoples.length - 1;
        // 表示左右
        int lr;
        // 表示步数
        int step;
        while (m-- > 0) {
            lr = Integer.parseInt(sc.next());
            step = Integer.parseInt(sc.next());

            // 向左 内左 实际上是数组向右
            //     外左 实际上是数组向左   反之亦然
            // 就可以看出，相等的时候向右
            // 不相等的时候向左
            if (lr == peoples[index].outOrIn) {
                index = (index + step) % peoples.length;

            } else {
                index = (index - step + peoples.length) % peoples.length;
            }
        }

        System.out.println(peoples[index].name);
    }

    static class People {
        public String name;
        public int outOrIn;
    }
}
